package com.qingke.oo;

public class MyTime {
	private int hour = 0;
	private int minute = 0;
	private int second = 0;
	
	public MyTime(){
		
	}
	
	public MyTime(int hour,int minute,int second){
		if(hour>24 || hour<0 || minute>59 || minute<0 || second>59 || second<0){
			throw new IllegalArgumentException();
			
		}
		this.hour = hour;
		this.minute = minute;
		this.second = second;
	}
	
	public void setTime(int hour,int minute,int second){
		if(hour>24 || hour<0 || minute>59 || minute<0 || second>59 || second<0){
			throw new IllegalArgumentException();
			
		}
		this.hour = hour;
		this.minute = minute;
		this.second = second;
	}
	
	public int getHour(){
		return hour;
	}
	
	public int getMinute(){
		return minute;
	}
	
	public int getSecond(){
		return second;
	}
	
	public void setHour(int hour){
		if(hour>24 || hour<0)
			throw new IllegalArgumentException();
		this.hour = hour;
	}
	
	public void setMinute(int minute){
		if(minute>59||minute<0)
			throw new IllegalArgumentException();
		this.minute = minute;
	}
	
	public void setSecond(int second){
		if(minute<0 || minute>59)
			throw new IllegalArgumentException();
	
		
		this.second = second;
	}
	
	public String toString(){
		String a = "";
		String b = "";
		String c = "";
		if(hour>9)
			a=a+hour;
		else
			a="0"+hour;
		
		if(minute>9)
			b=b+minute;
		else
			b="0"+minute;
		
		if(second>9)
			c=c+second;
		else
			c="0"+second;
		return a+":"+b+":"+c;
	}
	
	public MyTime nextSecond(){
		if(second==59) {
			this.setMinute(minute+1);
			this.setSecond(0);
		}
		this.setSecond(second+1);
		return this;
	}
	
	public MyTime nextMinute(){
		if(minute==59) {
			this.setHour(hour+1);
			this.setMinute(0);
		}			
		this.setMinute(minute+1);
		return this;
	}
	
	public MyTime nextHour(){
		if(hour==23)
			this.setHour(0);
		this.setHour(hour+1);
		return this;
	}
	
	public MyTime previousSecond(){
		if(second<1)
			throw new IllegalArgumentException();
		this.setSecond(second-1);
		return this;
	}
	
	public MyTime previousMinute(){
		if(minute<1)
			throw new IllegalArgumentException();
		this.setMinute(minute-1);
		return this;
	}
	
	public MyTime previousHour(){
		if(hour<1)
			throw new IllegalArgumentException();
		this.setHour(hour-1);
		return this;
	}
	
}
